<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\logic;

/**
 * currency逻辑
 */
class Currency extends LogicBase
{
    

    
    /**
     * 获取currency列表
     */
    public function getcurrencyList($where = [], $field = 'a.*,c.name as category_name', $order = '')
    {
        
        $this->modelwallet->alias('a');
        

        
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
//        $where['a.is_currency']=1;
        
        return $this->modelwallet->getList($where, $field, $order);
    }
    
    /**
     * 获取currency列表搜索条件
     */
    public function getWhere($data = [])
    {
        
        $where = ['is_virtual'=>$data['is_virtual']];
        !empty($data['search_data']) && $where['a.name'] = ['like', '%'.$data['search_data'].'%'];
        
        return $where;
    }
    
    /**
     * currency信息编辑
     */
    public function currencyEdit($data = [])
    {
        
        $validate_result = $this->validatecurrency->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validatecurrency->getError()];
        }
        
        $url = url('currencyList');


        $where['a.is_currency']=1;
        $result = $this->modelwallet->setInfo($data);
        $list=$this->modelwallet->getList(['is_virtual'=>$data['is_virtual']], '*', 'id asc',false);
        if($data['is_virtual']==1){
            cache('virtual_currency',$list);
        }else{
            $url = url('currency_exchange_list');
            cache('currency',$list);
        }
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        $result && action_log($handle_text, 'currency' . $handle_text . '，name：' . $data['name']);
        
        return $result ? [RESULT_SUCCESS, 'currency操作成功', $url] : [RESULT_ERROR, $this->modelwallet->getError()];
    }

    /**
     * 获取currency信息
     */
    public function getcurrencyInfo($where = [], $field = 'a.*')
    {
        
        $this->modelwallet->alias('a');
        

        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];

        // $where['a.is_currency']=1;
        return $this->modelwallet->getInfo($where, $field);
    }
    


    /**

    
    /**
     * currency删除
     */
    public function currencyDel($where = [])
    {
        
        $result = $this->modelwallet->deleteInfo($where);
        
        $result && action_log('删除', 'currency删除，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, 'currency删除成功'] : [RESULT_ERROR, $this->modelwallet->getError()];
    }
}
